﻿<UserControl x:Class="Wpf2.Views.OutInventory"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Wpf2.Models"
             mc:Ignorable="d" 
             Height="Auto" Width="Auto">
    <UserControl.Resources>
        <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </UserControl.Resources>
    <StackPanel Height="700" Width="Auto" VerticalAlignment="Top">
        <StackPanel Width="Auto" Margin="0,5,0,5" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" x:Name="PanelButtonCatalogs" Orientation="Vertical" Height="50">
            <ListView Height="50" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" HorizontalAlignment="Left"  Name="lvCatalog" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="0" BorderThickness="0" Width="Auto">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"></StackPanel>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="Blue" BorderThickness="1" Height="30" Background="#FF16499A">
                            <StackPanel Orientation="Horizontal" Height="30" Width="120" HorizontalAlignment="Center">
                                <Image Source="/Wpf2;component/Images/catalog.png" Width="30" Height="30"/>
                                <TextBlock Text="{Binding CatalogName}" VerticalAlignment="Center" Margin="2,0,0,0" Foreground="White"/>
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackPanel>
        <StackPanel Name="panelOfCustomer" Margin="0,0,0,5" Height="50" Orientation="Horizontal" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
            <StackPanel Height="30" Width="80" Orientation="Horizontal" Background="#FF16499A" Margin="5,0,0,0">
                <Label Background="#FF0050EF" Foreground="White"> Đá HC</Label>
                <CheckBox Name="chkDahoacuong" Height="30" Margin="8,7,5,5" IsChecked="{Binding IsMarble, UpdateSourceTrigger=PropertyChanged}" Checked="CaculationPayment" Unchecked="CaculationPayment"/>
            </StackPanel>
            <Label Margin="10,0,0,0" Height="30" Target="{Binding ElementName=txtUserID}" Content="_Mã NV:" Background="#FF0050EF" Foreground="White"></Label>
            <TextBox Padding="5" x:Name="txtUserID" Height="30" Width="100" Margin="0,0,10,0" Text="{Binding ID_USER, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Background="#FF0050EF" Foreground="#FFFCFCFC"/>
                <Label Height="30" Target="{Binding ElementName=txtCustomer}" Content="_Khách hàng:" Background="#FF0050EF" Foreground="White"></Label>
                <TextBox Padding="5" x:Name="txtCustomerName" Height="30" Text="{Binding CusName, UpdateSourceTrigger=LostFocus}" Width="100" Margin="0,0,10,0" Foreground="#FFFCFCFC" Background="#FF0050EF"></TextBox>
                <Label Target="{Binding ElementName=txtAddress}" Height="30" Content="Địa _chỉ:" Foreground="White" Background="#FF0050EF"></Label>
                <TextBox Padding="5" x:Name="txtCustomerAddress" Height="30" Text="{Binding Address, UpdateSourceTrigger=PropertyChanged}" Width="130" Margin="0,0,10,0" Background="#FF0050EF" Foreground="#FFFCFCFC"></TextBox>
                <Label Target="{Binding ElementName=txtPhoneNumber}" Height="30" Content="Điện _thoại:" Background="#FF0050EF" Foreground="White"></Label>
                <TextBox Padding="5" x:Name="txtCustomerPhoneNumber" Text="{Binding Phone, UpdateSourceTrigger=PropertyChanged}" Height="30" Width="130" PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Foreground="#FFFCFCFC" Background="#FF0050EF"></TextBox>
            
<StackPanel Margin="10,0,0,0" Width="70" Height="30" Orientation="Horizontal">
                <Button x:Name="btnSaveOrder"  Width="40" Background="#16499A">
                    <TextBlock Foreground="#FFFCFCFC"> Lưu</TextBlock>
                </Button>
                <StackPanel Width="30" Height="30" Background="#FF0050EF">
                    <Image Source="/Wpf2;component/Images/Save.png" />
                </StackPanel>
            </StackPanel>
           
            <StackPanel Margin="10,0,20,0" Width="70" Height="30" Orientation="Horizontal">
                <Button x:Name="btnPrint"  Width="40" Background="#16499A" >
                    <TextBlock Foreground="#FFFCFCFC"> In</TextBlock>
                </Button>
                <StackPanel Width="30" Height="30" Background="#FF0050EF">
                    <Image Source="/Wpf2;component/Images/print.png" />
                </StackPanel>
            </StackPanel>
        </StackPanel>
        <StackPanel  HorizontalAlignment="Center">
            <DataGrid Grid.Row="0" x:Name="dtgInventory" Background="White" Height="400" AutoGenerateColumns="False" CanUserAddRows="False" Margin="0,0,0,5" AlternatingRowBackground="PaleTurquoise">
                <DataGrid.Resources>
                    <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
                </DataGrid.Resources>
                <DataGrid.RowHeaderTemplate>
                    <DataTemplate>
                        <TextBlock  Width="20" Text="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}, Mode=FindAncestor}}"/>
                    </DataTemplate>
                </DataGrid.RowHeaderTemplate>
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Mã Sản Phẩm">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                    <TextBox Height="20" Width="80" TextChanged="TxtProductNameTextChanged" Text="{Binding ProductId,UpdateSourceTrigger=PropertyChanged}" LostFocus="TxtProductNameLostFocus" KeyDown="TxtProductNameKeydown" BorderThickness="0" Background="{x:Null}"/>
                                    <ComboBox SelectionChanged="ComboBoxSelectionChanged" Visibility="Hidden"  IsTabStop="False" IsSynchronizedWithCurrentItem="True" ></ComboBox>
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="Tên Sản Phẩm" Width="150" Binding="{Binding ProductName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" CanUserSort="False"/>
                    <DataGridTextColumn Header="Mô Tả" Binding="{Binding ProductDescription, UpdateSourceTrigger=PropertyChanged}" Width="250" IsReadOnly="True" CanUserSort="False"/>
                    <!-- BeginRegion-->
                        <!-- DataGird không thể sử dụng elementName => phải dùng Source-->
                        <!-- hiện lỗi không sao! cứ bỏ qua-->
                        <!-- Xử lý dạng Đá Hoa Cương (9/5/2014)-->
                    <DataGridTemplateColumn Header="Dài" Width="40" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding ProductHeight, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment" BorderThickness="0"  Background="{x:Null}"></TextBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Rộng" Width="40" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding ProductWidth, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment"  BorderThickness="0" Background="{x:Null}"></TextBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <!-- EndRegion-->
                    <DataGridTemplateColumn Header="Số Lượng">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding InventoryCount, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" TextChanged="TxtInvetoryCountTextChanged" Background="{x:Null}"></TextBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <!-- Chức năng Đá Hoa Cương: thêm ngày (9/5/14)-->
                    <DataGridTextColumn Header="M2" Binding="{Binding ProductM2, UpdateSourceTrigger=PropertyChanged}" Width="40" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <DataGridTextColumn Header="Giá" Binding="{Binding Price, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\} VNĐ}" IsReadOnly="True" Width="80" CanUserSort="False"/>
                    <DataGridTemplateColumn Header="Giá sỉ">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsCostPrice, UpdateSourceTrigger=PropertyChanged}" Checked="chboxIsCostPrice_checked" Unchecked="chboxIsCostPrice_checked"></CheckBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTextColumn Header="Đơn vị" Binding="{Binding UnitName, UpdateSourceTrigger=PropertyChanged}" Width="80" IsReadOnly="True" CanUserSort="False"/>
                    <DataGridTextColumn Header="Nhóm" Binding="{Binding catalog.CatalogName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="80" CanUserSort="False"/>
                    <DataGridTextColumn Header="Thành tiền" Binding="{Binding TotalOutPayment, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\} VNĐ}" IsReadOnly="True" Width="*" CanUserSort="False"/>
                </DataGrid.Columns>
            </DataGrid>
        </StackPanel>
        <StackPanel>
            <Grid Grid.Row="3" Width="Auto" Background="#FFF6F6F6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

                <StackPanel HorizontalAlignment="Right" Width="Auto" Orientation="Horizontal" x:Name="panelOfPaymentInfomation" Background="#FFF6F6F6" Grid.ColumnSpan="2" Margin="0,0,0,0">
                    <StackPanel  Margin="0,5,10,10">
                    <WrapPanel HorizontalAlignment="Right" Margin="0,0,0,10">
                            <Label Width="80" Height="30" Target="{Binding ElementName=txtOLD_DEBTS}" Content="_Nợ cũ:" Background="#FF0050EF" Foreground="White" ></Label>
                            <TextBox Padding="5" x:Name="txtOLD_DEBTS" Text="{Binding OldDebts, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\}}" TextAlignment="Right" Height="30" Width="130"  PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Background="#FF0050EF" Foreground="White"/>
                    </WrapPanel>
                    <WrapPanel HorizontalAlignment="Right" >
                        <Label Width="80" Target="{Binding ElementName=txtPRE_PAID}" Content="_Gửi trước:" Background="#FF0050EF" Foreground="White"></Label>
                            <TextBox Padding="5" x:Name="txtPRE_PAID" Text="{Binding PrePaid, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\}}" TextAlignment="Right" Height="30" Width="130"  PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Foreground="#FFFCFCFC" Background="#FF0050EF"></TextBox>
                    </WrapPanel>
                </StackPanel>

                <StackPanel Margin="0,5,5,5">
                    <WrapPanel HorizontalAlignment="Right" Margin="0,0,0,10">
                        <Label Width="80" Height="30" Target="{Binding ElementName=txtSumOut}" Content="Tổng t_oa:" Background="#FF0050EF" Foreground="White" ></Label>
                            <TextBox Padding="5" x:Name="txtSumOut" IsEnabled="False" Text="{Binding SumOut, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\} VNĐ}" TextAlignment="Right" Height="30" Width="130"  PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Background="#FF0050EF" Foreground="#FFFCFCFC"></TextBox>
                    </WrapPanel>
                    <WrapPanel HorizontalAlignment="Right" Margin="0,0,0,10">
                        <Label Width="80" Height="30" Target="{Binding ElementName=txtTotal}" Content="Tổn_g cộng:" Background="#FF0050EF" Foreground="White"></Label>
                            <TextBox Padding="5" x:Name="txtTotal" IsEnabled="False" Text="{Binding TotalPayment, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\} VNĐ}" TextAlignment="Right" Height="30" Width="130" PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Background="#FF0050EF" Foreground="#FFFCFCFC"></TextBox>
                    </WrapPanel>
                    <WrapPanel HorizontalAlignment="Right">
                        <Label Width="80" Height="30" Target="{Binding ElementName=txtRemain}" Content="Còn _lại:" Background="#FF0050EF" Foreground="White"></Label>
                            <TextBox Padding="5" x:Name="txtRemain" IsEnabled="False" Text="{Binding Remain, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\} VNĐ}" TextAlignment="Right" Height="30" Width="130" PreviewTextInput="TxtAcceptNumbericPreviewTextInput" Background="#FF0050EF" Foreground="#FFFCFCFC"></TextBox>
                    </WrapPanel>
                </StackPanel>
            </StackPanel>
        </Grid>
            </StackPanel>
        </StackPanel>
</UserControl>
